#!/usr/bin/python
#-*-<coding=UTF-8>-*-

"""
"""

import wx
class TestFrame(wx.Frame):
    def __init__(self):
        wx.Frame.__init__(self,parent=None,id=-1,title="Real world test")
        panel = wx.Panel(self)

        #创建
        topLabel = wx.StaticText(parent=panel,id=-1,label="Account Information")
        topLabel.SetFont(wx.Font(18,wx.SWISS,wx.NORMAL,wx.BOLD))

        nameLabel = wx.StaticText(parent=panel,id=-1,label="Name")
        name = wx.TextCtrl(parent=panel,id=-1,value="")

        addrLabel = wx.StaticText(parent=panel,id=-1,label="Address:")
        addr_a = wx.TextCtrl(parent=panel,id=-1,value="")
        addr_b = wx.TextCtrl(parent=panel,id=-1,value="")

        cstLabel = wx.StaticText(panel,id=-1,label="City,State,Zip:")
        city = wx.TextCtrl(parent=panel,id=-1,value="",size=(150,-1))
        state = wx.TextCtrl(parent=panel,id=-1,value="",size=(50,-1))
        zipos = wx.TextCtrl(panel,-1,"",size=(70,-1))

        phoneLabel = wx.StaticText(parent=panel,id=-1,label="Phone:")
        phone = wx.TextCtrl(panel,-1,"")

        emailLabel = wx.StaticText(panel,-1,"Email:")
        email = wx.TextCtrl(panel,-1,"")

        saveButton = wx.Button(panel,-1,"Save")
        canelButton = wx.Button(panel,-1,"Canel")

        """
        mainSizer管理所有对象.是一个垂直的boxSizer. 
        主要的对像有topLabel,StaticLine,addrSizer,btnSizer.
        其中addrSizer又管理着地址相关的信息控件.
        btnSizer管理着两个button控件.
        """
        #首先将标题和分隔线添加进去;
        mainSizer = wx.BoxSizer(wx.VERTICAL)
        mainSizer.Add(topLabel,0,wx.ALL,5)
        mainSizer.Add(wx.StaticLine(panel),0,wx.EXPAND|wx.TOP|wx.BOTTOM,5)

        """
        addrSizer是一个grid sizer
        """
        #创建一个2列的gridSizer. 同时设置为行方向比例增长.
        addrSizer = wx.FlexGridSizer(cols=2,hgap=5,vgap=5)
        addrSizer.AddGrowableCol(1)

        addrSizer.Add(nameLabel,0,wx.ALIGN_RIGHT|wx.ALIGN_CENTER_VERTICAL)
        addrSizer.Add(name,0,wx.EXPAND)

        addrSizer.Add(addrLabel,0,wx.ALIGN_RIGHT|wx.ALIGN_CENTER_VERTICAL)
        addrSizer.Add(addr_a,0,wx.EXPAND)

        #这是一个间隙设置
        addrSizer.Add((10,10))
        addrSizer.Add(addr_b,0,wx.EXPAND)

        addrSizer.Add(cstLabel,0,wx.ALIGN_RIGHT|wx.ALIGN_CENTER_VERTICAL)
        #添加一个水平方向的boxSizer.用来放置city,state,zipos.
        cstSizer = wx.BoxSizer(wx.HORIZONTAL)
        cstSizer.Add(city,1)
        cstSizer.Add(state,0,wx.LEFT|wx.RIGHT)
        cstSizer.Add(zipos)
        addrSizer.Add(cstSizer,0,wx.EXPAND)

        addrSizer.Add(phoneLabel,0,wx.ALIGN_RIGHT|wx.ALIGN_CENTER_VERTICAL)
        addrSizer.Add(phone,0,wx.EXPAND)

        addrSizer.Add(emailLabel,0,wx.ALIGN_RIGHT|wx.ALIGN_CENTER_VERTICAL)
        addrSizer.Add(email,0,wx.EXPAND)

        mainSizer.Add(addrSizer,0,wx.EXPAND|wx.ALL,10)

        btnSizer = wx.BoxSizer(wx.HORIZONTAL)
        btnSizer.Add((20,20),1)
        btnSizer.Add(saveButton)
        btnSizer.Add((20,20),1)
        btnSizer.Add(canelButton)
        btnSizer.Add((20,20),1)

        mainSizer.Add(btnSizer,0,wx.EXPAND|wx.BOTTOM,10)

        panel.SetSizer(mainSizer)
        mainSizer.Fit(self)
        mainSizer.SetSizeHints(self)


if __name__ == "__main__":
    app = wx.PySimpleApp()
    TestFrame().Show()
    app.MainLoop()
        
